namespace SimpleWebServices.Security.Principal
{
    using System;
    using System.Security.Principal;
    using System.Xml;
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class AnonymousUserFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<AnonymousUser>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IIdentity>()
                .Implements<IPrincipal>()
                .Implements<IXmlSerializable>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new AnonymousUser());
        }

        [Fact]
        public void deserialize()
        {
            Assert.Throws<InvalidOperationException>(() => "<user />".Deserialize<AnonymousUser>());
        }

        [Fact]
        public void serialize()
        {
            Assert.Throws<InvalidOperationException>(() => new AnonymousUser().Serialize());
        }

        [Fact]
        public void prop_AuthenticationType()
        {
            Assert.True(new PropertyExpectations(typeof(AnonymousUser).GetProperty("AuthenticationType"))
                .TypeIs<string>()
                .DefaultValueIs("None")
                .Result);
        }

        [Fact]
        public void prop_IsAuthenticated()
        {
            Assert.True(new PropertyExpectations(typeof(AnonymousUser).GetProperty("IsAuthenticated"))
                .TypeIs<bool>()
                .DefaultValueIs(false)
                .Result);
        }

        [Fact]
        public void prop_Identity()
        {
            Assert.True(new PropertyExpectations(typeof(AnonymousUser).GetProperty("Identity"))
                .TypeIs<IIdentity>()
                .DefaultValueIsNotNull()
                .Result);
        }

        [Fact]
        public void prop_Name()
        {
            Assert.True(new PropertyExpectations(typeof(AnonymousUser).GetProperty("Name"))
                .TypeIs<string>()
                .DefaultValueIs("Guest")
                .Result);
        }

        [Fact]
        public void op_IsInRole_string()
        {
            Assert.False(new AnonymousUser().IsInRole("User"));
        }

        [Fact]
        public void op_IsInRole_stringGuest()
        {
            Assert.True(new AnonymousUser().IsInRole("Guest"));
        }

        [Fact]
        public void op_IsInRole_stringEmpty()
        {
            Assert.False(new AnonymousUser().IsInRole(string.Empty));
        }

        [Fact]
        public void op_IsInRole_stringNull()
        {
            Assert.False(new AnonymousUser().IsInRole(null as string));
        }

        [Fact]
        public void IXmlSerializable_op_GetSchema()
        {
            Assert.Throws<NotSupportedException>(() => (new AnonymousUser() as IXmlSerializable).GetSchema());
        }

        [Fact]
        public void IXmlSerializable_op_ReadXml_XmlReaderNull()
        {
            Assert.Throws<ArgumentNullException>(() => (new AnonymousUser() as IXmlSerializable).ReadXml(null as XmlReader));
        }

        [Fact]
        public void IXmlSerializable_op_WriteXml_XmlWriterNull()
        {
            Assert.Throws<ArgumentNullException>(() => (new AnonymousUser() as IXmlSerializable).WriteXml(null as XmlWriter));
        }
    }
}